package com.centling.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.centling.business.CustomerBean;
import com.centling.dao.ICustomerDAO;
import com.centling.dao.IUtilsDAO;
import com.centling.service.ICustomerService;

@Service
@Transactional
public class CustomerService implements ICustomerService{

	private Logger log = Logger.getLogger(CustomerService.class);
	
	@Resource
	private ICustomerDAO customerDAO;
	
	@Resource
	private IUtilsDAO utilsDAO;

	@SuppressWarnings("rawtypes")
	public List findAll() {
		List list = customerDAO.findAll();
		for (Object o:list){
			log.info(o.toString());
		}
		return list;
	}

	@Transactional
	public boolean save(List<CustomerBean> customers) {
		for (CustomerBean cb:customers){
			int fItemID = utilsDAO.getICMaxNum("t_item");
			if (fItemID!=-1){
				customerDAO.save(cb,fItemID,null);
				utilsDAO.setICMaxNum("t_item");
				if (cb.getF_customer_type()!=null && cb.getF_customer_type().equals("是")){
					utilsDAO.processT_itemWhenInsertCustomer(fItemID, cb.getF_other_customer_code(), cb.getfName());
				}
			}
		}
		return true;
	}

}
